#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>


#define CONV(v) (struct sockaddr *)(v)
class InterAddr
{
public:
    void PortNet2Host()
    {
        _port = ::ntohs(_addr.sin_port);
    }

    void IpNet2Host()
    {
        char buffer[64];
        const char*ip=inet_ntop(AF_INET,&_addr.sin_addr,buffer,sizeof(buffer));
        _ip=ip;
    }


    InterAddr(sockaddr_in &sock) : _addr(sock)
    {
        PortNet2Host();
        IpNet2Host();
    }
    InterAddr(uint16_t port)
    {
       _addr.sin_family=AF_INET;
       _addr.sin_port=htons(port);
       _addr.sin_addr.s_addr=INADDR_ANY;
        PortNet2Host();
        IpNet2Host();
    }
    socklen_t NetAddrLen() { return sizeof(_addr); }
    struct sockaddr *NetAddr() { return CONV(&_addr); }
    uint16_t Port(){ return _port; }
private:
    struct sockaddr_in _addr;
    uint16_t _port;
    std::string _ip;
};